package com.settlement.system.controller;

import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.reply.ObjectDataResponse;
import com.settlement.system.service.IBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import com.settlement.system.model.entity.common.TblWpVendorConfig;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;

import com.settlement.system.service.ITblWpVendorConfigService;

import java.util.Date;

/**
 * 唯品会商户配置 前端控制器
 * @author Ximi
 * @since 2020-04-15
 */

@RestController
@RequestMapping("/wpVendorConfig")
@Slf4j
public class TblWpVendorConfigController extends BaseController<TblWpVendorConfig> {

    @Resource
    private ITblWpVendorConfigService tblWpVendorConfigService;

    @Override
    public IBaseService init() {
        return tblWpVendorConfigService;
    }

    /**
     * 删除主数据时连明细数据也一并删除
     * @param model
     * @return
     * @throws ServiceException
     */
    @RequestMapping(value = "deleteMD",method = {RequestMethod.POST})
    public  ObjectDataResponse deleteMD(@RequestBody TblWpVendorConfig model, HttpServletRequest request) {
        try {
            tblWpVendorConfigService.deleteMD(model);
            return new ObjectDataResponse(200,"删除成功");
        } catch (Exception ex){
            log.info("删除数据异常",ex);
            return new ObjectDataResponse(500,"删除失败，请联系管理员！");
        }
    }

    @Override
    protected void setModelValue(TblWpVendorConfig model) throws Exception {
        model.setBillScheduleLasterTime(new Date());
        model.setDiscountScheduleLasterTime(new Date());
        model.setItemDiffScheduleLasterTime(new Date());
    }

    /**
     * 更新状态
     * @param model
     * @return
     * @throws ServiceException
     */
    @RequestMapping(value = "changeStatus",method = {RequestMethod.POST})
    public  ObjectDataResponse changeStatus(@RequestBody TblWpVendorConfig model) {
        try {
            tblWpVendorConfigService.updateStatus(model);
            return new ObjectDataResponse(200,"更新成功");
        } catch (Exception ex){
            log.info("更新数据异常",ex);
            return new ObjectDataResponse(500,"更新失败，请联系管理员！");
        }
    }
}

